package com.st.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.st.service.GoodsService;
import com.st.vo.GetGoodsDetailListForIndex_1Vo;
import com.st.vo.GetGoodsDetailListForIndex_2Vo;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;

import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.st.dao.GoodsDetailMapper;
import com.st.pojo.GoodsDetail;
import com.st.service.GoodsDetailService;
@Service
public class GoodsDetailServiceImpl extends ServiceImpl<GoodsDetailMapper, GoodsDetail> implements GoodsDetailService{

    @Resource
    private GoodsDetailMapper goodsDetailMapper;

    @Resource
    private GoodsService goodsService;


    @Override
    public int batchInsert(List<GoodsDetail> list) {
        return baseMapper.batchInsert(list);
    }

    @Override
    public List<GetGoodsDetailListForIndex_1Vo> getGoodsDetailListForIndex_1() {
        //1.获取全部数据
        QueryWrapper<GoodsDetail> qw = new QueryWrapper<>();
        qw.select(GoodsDetail.COL_ID,GoodsDetail.COL_NAME,GoodsDetail.COL_ICON_URL);
        List<GoodsDetail> goodsDetails = goodsDetailMapper.selectList(null);
        //2.过滤数据
        if(goodsDetails != null && goodsDetails.size() > 0){
            List<GetGoodsDetailListForIndex_1Vo> goodsDetailListForIndex1Vos = new ArrayList<>();
            for (GoodsDetail goodsDetail : goodsDetails) {
                GetGoodsDetailListForIndex_1Vo g = new GetGoodsDetailListForIndex_1Vo();
                g.setId(goodsDetail.getId());
                g.setName(goodsDetail.getName());
                g.setIconUrl(goodsDetail.getIconUrl());

                goodsDetailListForIndex1Vos.add(g);
            }
            return goodsDetailListForIndex1Vos;
        }

        return null;
    }


    @Override
    public List<GetGoodsDetailListForIndex_2Vo> getGoodsDetailListForIndex_2(Integer pageNumber, Integer pageSize) {
        //1.获取基础数据
        QueryWrapper<GoodsDetail> qw = new QueryWrapper<>();
        qw.select(GoodsDetail.COL_ID,GoodsDetail.COL_TARGET,GoodsDetail.COL_TIP);
        List<GoodsDetail> goodsDetails = goodsDetailMapper.selectList(null);
        //2.过滤返回数据
        if(goodsDetails != null && goodsDetails.size() > 0){
            List<GetGoodsDetailListForIndex_2Vo> goodsDetailListForIndex2Vos = new ArrayList<>();
            for (GoodsDetail goodsDetail : goodsDetails) {
                GetGoodsDetailListForIndex_2Vo g = new GetGoodsDetailListForIndex_2Vo();
                g.setId(goodsDetail.getId());
                g.setTarget(goodsDetail.getTarget());
                g.setTip(goodsDetail.getTip());
                //3.查询每个分类下两个商品图片
                // 通过分类编号去商品表查询该分类下的两个商品，并获取他们的图片
                List<String> goodsImgs = goodsService.getTwoGoodsImgByGoodsDetailId(goodsDetail.getId());
                g.setGoodsImgs(goodsImgs);

                goodsDetailListForIndex2Vos.add(g);
            }

            return goodsDetailListForIndex2Vos;
        }

        //4.返回
        return null;
    }
}
